package com.handinfo.android.core.input;

import android.view.View;
import android.view.inputmethod.BaseInputConnection;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.uicontrols.DWCharsDetection;
import com.handinfo.android.uicontrols.controls.DWTextbox;

public class DWInputConnection extends BaseInputConnection
{
	
	public DWInputConnection(View targetView, boolean fullEditor)
	{
		super(targetView, fullEditor);
	}

	public boolean commitText(CharSequence text, int newCursorPosition)
	{
		// 提交字符到需要输入的控件，可在此次监听输入的字符值
		if (text == null) {
			return false;
		}
		DWGameManager.getInstance().getCurrentActivity().getGameView().inputText += text.toString();

		DWTextbox tb = DWKey.getInstance().m_cache_text;
		if (tb != null) {
			if (DWCharsDetection.detectionSpecific(text.toString())) {
				return false;
			}
			if (tb.getText() == null) {
				tb.setText(text.toString());
			} else {
				tb.setText(tb.getText() + text.toString());
			}
		}
		DWGameManager.getInstance().getCurrentActivity().getGameView().requestFocus();
		return true;
	}
}
